<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>javascript其他基本语法</title>
</head>
<body>
按F12打开控制台
<script>
    //数据类型
    let a = 10;
    let b = "10";
    let c = true;
    let d = null;
    let e;
    let e2 = undefined;

    console.log("typeof a = " + typeof a);//typeof a = number
    console.log("typeof b = " + typeof b);//typeof b = string
    console.log("typeof c = " + typeof c);//typeof c = boolean
    console.log("typeof d = " + typeof d);//typeof d = object
    console.log("typeof e = " + typeof e);//typeof e = undefined
    console.log("typeof e2 = " + typeof e2);//typeof e2 = undefined
    console.log("typeof f = " + typeof f);//typeof f = undefined

    //全等问题
    let a2 = 10;
    console.log(a2 == "10"); //true,==只看值,不管类型
    console.log(a2 === "10"); //false,===既看值,也看类型
    console.log(a2 === 10); //true


    //其他类型作为布尔值的默认值
    let g = 10;
    let g2 = 0;
    let g3 = NaN;//Not a Number

    let h = "abc";
    let h2 = "";

    let i;
    let j = null;



    if (g) {
        console.log(g + "这个条件是true")
    } else {
        console.log(g + "这个条件是false")
    }//10这个条件是true

    if (g2) {
        console.log(g2 + "这个条件是true")
    } else {
        console.log(g2 + "这个条件是false")
    }//0这个条件是false

    if (g3) {
        console.log(g3 + "这个条件是true")
    } else {
        console.log(g3 + "这个条件是false")
    }//NaN这个条件是false

    if (h) {
        console.log(h + "这个条件是true")
    } else {
        console.log(h + "这个条件是false")
    }//abc这个条件是true

    if (h2) {
        console.log(h2 + "这个条件是true")
    } else {
        console.log(h2 + "这个条件是false")
    }//这个条件是false

    if (i) {
        console.log(i + "这个条件是true")
    } else {
        console.log(i + "这个条件是false")
    }//undefined这个条件是false

    if (j) {
        console.log(j + "这个条件是true")
    } else {
        console.log(j + "这个条件是false")
    }//null这个条件是false

    //字符串类型转为数字
    let k = "101"
    // let l = +k;//取正
    let l = -k;//取负

    console.log(l)//-101
    console.log(typeof l)//number

    let k2 = "abc100"
    let l2 = +k2;
    console.log(l2)//NaN
    console.log(typeof l2)//number

    /*变量应该先定义，再使用*/
    console.log(f);//Uncaught ReferenceError: f is not defined
</script>
</body>
</html>